<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="/Public/Admin/css/shortcut icon" href="favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/cityPicker/city-picker.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/Public/Admin/css/edit.css" rel="stylesheet"/>
	<link href="/Public/Admin/css/selector/selectorstyle.css" rel="stylesheet"/>
    
</head>
<body class="gray-bg">
	
	<body class="gray-bg body_box">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
        	
        	<form class="form-horizontal m-t js-ajax-forms" id="signupForm" action="<?php echo U('User/add');?>" method="post" enctype="multipart/form-data">
    <?php $canRole = true;?>
            <div class="col-sm-8 <?php if(!$canRole){echo 'col-sm-offset-2';}?>">

                <div class="ibox float-e-margins">

                    <div class="ibox-content">
                    	
                    	<div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">用户名 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="UserName" name="UserName" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
		                    </div>
		                </div>

		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">姓名 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="TrueName" name="TrueName" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
		                    </div>
		                </div>
		                
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">密码 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="Password" name="Password" class="form-control" type="password">
		                    </div>
		                </div>
		                
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">确认密码 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                       <input id="ConfirmPassword" name="ConfirmPassword" class="form-control" type="password">
		                    </div>
		                </div>

						<div class="form-group row" >
							<label class="col-md-3 col-sm-2 control-label text-right ">部门</label>
							<div class="col-md-4 col-sm-6 ">
								<input id='ApplyUserID' name='ApplyUserID' value="" type="hidden">
								<input id="ApplyUserName" name="ApplyUserName" class="form-control selector-icon"  onclick="openselector('ApplyUserID','ApplyUserName')" data-toggle="modal" data-target="#myModal" type="text"  value="">
							</div>
						</div>
		                
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">性别 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <select class="form-control m-b" id="Sex" name="Sex" aria-required="true" aria-invalid="true" class="error">
                                    <option value="">请选择用户性别</option>
                                    <?php if(is_array($Sex)): foreach($Sex as $key=>$vo): $selected = $key==1?'selected':''; ?>
                                        <option <?php echo ($selected); ?> value="<?php echo ($key); ?>"><?php echo ($vo); ?></option><?php endforeach; endif; ?>
                                </select>
		                    </div>
		                </div>

		                
		                <div class="form-group row">
		                    <label class="col-md-3 col-sm-2 control-label text-right ">出生年月</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input placeholder="出生年月" class="form-control layer-date laydate-icon" id="start" name="Birthday" value="" style="width: 250px;">
		                    </div>
		                </div>

                        
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">所在城市</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="City" class="form-control" name="City" type="text" data-toggle="city-picker" value="">
		                    </div>
		                </div>


		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">联系地址</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="Address" name="Address" class="form-control" type="text">
		                    </div>
		                </div>
		               
                        
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">手机 *</label>
		                    <div class="col-md-4 col-sm-6 ">
		                       <input id="Phone" name="Phone" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
		                    </div>
		                </div>
		                
		                
		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">E-mail</label>
		                    <div class="col-md-4 col-sm-6 ">
		                    	<input id="EMail" name="EMail" class="form-control" type="email">
		                    </div>
		                </div>


		                <div class="form-group row" >
		                    <label class="col-md-3 col-sm-2 control-label text-right ">身份证号</label>
		                    <div class="col-md-4 col-sm-6 ">
		                        <input id="CardNO" name="CardNO" class="form-control" type="text">
		                    </div>
		                </div>
						<div class="form-group row" >
							<label class="col-md-3 col-sm-2 control-label text-right ">排序号</label>
							<div class="col-md-4 col-sm-6 ">
								<input id="OrderNO" name="OrderNO" class="form-control" type="number">
							</div>
						</div>



		                <div class="form-group row">
		                    <label class="col-md-3 col-sm-2  control-label text-right">备注</label>
		                    <div class="col-md-6  col-sm-8 ">
		                        <textarea id="Remarks" name="Remarks" class="form-control diff-textarea" id="original" rows="6"></textarea>
		                    </div>
		                </div>
		      
                   
                        <div class="form-group row">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <a class="btn btn-white" href="javascript:void(0);" onclick="self.location=document.referrer;">返回</a>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <?php if($canRole){?>
            <div class="col-sm-4">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">角色</label>
                            <div class="col-sm-8">
                                <?php if(is_array($Roles)): foreach($Roles as $key=>$vo): ?><div class="checkbox checkbox-inline">
                                        <input type="checkbox" id="inlineCheckbox<?php echo ($key); ?>" name="RoleID[]" value="<?php echo ($vo["ID"]); ?>">
                                        <label for="inlineCheckbox<?php echo ($key); ?>"><?php echo ($vo["Name"]); ?></label>
                                    </div><?php endforeach; endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php }?>
        </form>
        </div>
    </div>
    
<script src="/Public/Admin/js/jquery.min.js?v=2.1.4"></script>
<script src="/Public/Admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/Public/Admin/js/plugins/layer/layer.min.js"></script>
<script src="/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/ajaxForm.js"></script>
<script src="/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script src="/Public/Admin/js/plugins/cityPicker/city-picker.data.js"></script>
<script src="/Public/Admin/js/plugins/cityPicker/city-picker.js"></script>
<script src="/Public/Admin/js/plugins/cityPicker/main.js"></script>
<script src="/Public/Admin/js/plugins/layer/laydate/laydate.js"></script>
	<script src="/Public/Admin/js/plugins/selector/selector.js"></script>
	<script src="/Public/Admin/js/plugins/selector/jquery.ztree.all.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
    	
    	/*
        $('.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
		*/

        var end = {
            elem: '#start',
            format: 'YYYY-MM-DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                
            }
        };
        laydate(end);
        
        
        $.validator.setDefaults({
            highlight: function (element) {
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                element.closest('.form-group').removeClass('has-error').addClass('has-success');
            },
            errorElement: "span",
            errorPlacement: function (error, element) {
                if (element.is(":radio") || element.is(":checkbox")) {
                    error.appendTo(element.parent().parent().parent());
                } else {
                    error.appendTo(element.parent());
                }
            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none "
        });

        $.validator.addMethod("isPhone", function (value, element) {
            var phone = /^1[34578]\d{9}$/;
            return phone.test(value);
        }, "请输入正确的手机号码");

        var icon = "<i class='fa fa-times-circle'></i> ";
        var form = $('form.js-ajax-forms');
        var formloading = false;
        //表单验证开始
        form.validate({
            //验证规则
            rules: {
                TrueName: "required",
                UserName: {
                    required: true
                },
                Password: {
                    required: true,
                    minlength: 6
                },
                ConfirmPassword: {
                    required: true,
                    minlength: 5,
                    equalTo: "#Password"
                },
                Sex: {
                    required: true
                },
                CardNO: {
                    rangelength: [15, 18]//输入值必须介于 15 和 18 之间。
                },
                Phone: {
                    isPhone: true,
                    required: true
                }
            },
            //验证未通过提示消息
            messages: {
                TrueName: icon + "请输入姓名",
                UserName: {
                    required: icon + "请输入用户名"
                },
                Password: {
                    required: icon + "请输入密码",
                    minlength: icon + "密码必须6个字符以上"
                },
                Sex: icon + "请选择性别",
                ConfirmPassword: {
                    required: icon + "请再次输入密码",
                    minlength: icon + "密码必须5个字符以上",
                    equalTo: icon + "两次输入的密码不一致"
                },
                CardNO: {
                    minlength: icon + "身份证位数长度有误"
                },
                Phone: {
                    required: icon + "请输入手机号码"
                }
            },
            //验证通过，提交表单
            submitHandler: function (forms) {
                if (formloading)
                    return;
                $(forms).ajaxSubmit({
                    url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                    dataType: 'json',
                    beforeSubmit: function (arr, $form, options) {
                        formloading = true;
                    },
                    success: function (data, statusText, xhr, $form) {
                        formloading = false;
                        if (data.status) {
                            //添加成功
                            swal({
                                        title: "继续添加？",
                                        text: "操作成功！",
                                        type: "success",
                                        showCancelButton: true,
                                        confirmButtonColor: "#DD6B55",
                                        confirmButtonText: "确认",
                                        cancelButtonText: "返回",
                                        closeOnConfirm: false,
                                        closeOnCancel: false
                                    },
                                    function (isConfirm) {
                                        if (isConfirm) {
                                            //swal("删除成功！", "您已经永久删除了这条信息。", "success");
                                            document.location.reload();
                                        } else {
                                            document.location.href = "<?php echo U('User/index');?>";
                                            //swal("已取消", "您取消了删除操作！", "error");
                                            return true;
                                        }
                                    });

                        } else {
                            swal("操作失败", data.info, "error");
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>